<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0, user-scalable=yes">
    <title>JQ测试</title>
    <script src="./JQ.js"></script>
    <style>
        .box {
            position: relative;
            left: 0;
            top: 0;
            width: 200px;
            height: 200px;
            margin: 10px;
        }
    </style>
</head>

<body>
    <div class="box">1</div>
    <div class="box">2</div>
    <div class="box">3</div>
    <div class="box">4</div>

    <script>
        // 使用 Jq 来获取元素 并添加样式
        $('.box').css({
            color: 'white',
            backgroundColor: 'black'
        })

        // 单独选择一个元素
        $('.box')
            .eq(2)
            .css({
                color: 'red',
                backgroundColor: 'orange'
            })

        // 给每个元素绑定点击事件
        $('.box').click(function () {
            console.log($(this).html())
            $(this)
                .fadeOut()
                .fadeIn()
                .animate({
                    left: '300px',
                    width: '100px'
                }, 2000, 'linear', function () {
                    console.log('动画完成！')
                })
        })
    </script>
</body>

</html>